<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<jsp:include page="/scripts/common/index.html"></jsp:include>
<jsp:include page="/scripts/dhtmlx/index.html"></jsp:include>
<jsp:include page="/scripts/jquery/index.html"></jsp:include>
<jsp:include page="/scripts/bootstrap/index.html"></jsp:include>
<link rel="stylesheet" href="${basepath }style/default.css">
</head>
<script type="text/javascript">
	var temp = false;
	function save() {
		$('#MyForm').bootstrapValidator('validate');
		if (temp) {
			$.ajax({
				type : 'POST' ,
				url : 'page/system/user/User/doAdd' ,
				data : $('#MyForm').serializeArray() ,
				dataType : "json" ,
				async : true ,
				cache : false ,
				jsonpCallback : "null" ,
				success : function(response, status, statusText) {
					if (response.status) {
						if (response.content == "有重复的用户账号，请重新输入！") {
							SN.alert.info("有重复的用户账号，请重新输入！");
						} else if (response.content == "添加成功！") {//type != 1
							//SN.clearFormValue("MyForm");
							SN.alert.info("添加成功！", function() {
								query();
								closeWindow();
							});
						} else if (response.content == "添加失败！") {
							//SN.clearFormValue("MyForm");
							SN.alert.info("添加失败！", function() {
								query();
								closeWindow();
							});
						}
					} else {
						alert(response.content);
					}
				} ,
				error : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
				} ,
				complete : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
				}
			});
		}
	}
	function query() {
		parent.query();
	}
	function closeWindow() {
		parent.w1.close();
	}
	//回到顶部按钮添加
	$(document).ready(function () {
            GP.goup({
                trigger: 100,
                bottomOffset: 30,
                locationOffset: 30,
                titleAsText: true,
               containerColor: '#7e7f7e'
            },"Panel_");
    });
		
	$(document).ready(function() {
		$('#MyForm').bootstrapValidator({
			message : 'This value is not valid' ,
			icon : {
				valid : 'glyphicon glyphicon-ok' ,
				invalid : 'glyphicon glyphicon-remove' ,
				validating : 'glyphicon glyphicon-refresh'
			} ,
			fields : {
				"map.userAccount" : {
					row : '.col-xs-3' ,
					validators : {
						notEmpty : {
							message : '不能为空'
						},
						regexp : {
							regexp : /^[a-zA-Z]{1}[a-zA-Z0-9]{2,29}$/ ,
							message : '以英文开头由为3-20位英文数字组成'
						}
					}
				} ,
				"map.userName" : {
					row : '.col-xs-3' ,
					validators : {
						notEmpty : {
							message : '不能为空'
						},
						stringLength: {
		                    min: 0,
		                    max: 15,
		                    message: '只能输入15个字符'
		                }
					}
				} /*,
				 "map.staffCode" : {
					row : '.col-xs-3' ,
					validators : {
						regexp : {
							regexp : /^([^0]|.{2,})$/ ,
							message : '请关联人员'
						}
					}
				} */
			}
		}).on('success.form.bv', function(e) {
			//alert("验证成功");
			temp = true;
			return temp;
		}).on('error.form.bv', function(e) {
			SN.alert.info("验证失败");
			temp = false;
			return temp;
		});
	});
</script>
<body>
	<form class="form-horizontal MyForm" id="MyForm" name="MyForm" method="post" target="MyFrame" enctype="multipart/form-data">
		<table class="contTable">
			<tr class="firstTr">
				<td>
					<button onclick="save()" class="btn btn-primary" type="button">
						<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>&nbsp;<span>保存</span>
					</button>
					<button onclick="closeWindow()" class="btn btn-primary" type="button">
						<span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span>&nbsp;<span>关闭</span>
					</button>
				</td>
			</tr>
			<tr style="height:auto">
				<td valign="top">
					<div id="Panel_" style="width:100%;height:200px;overflow-y:auto;">
						<div class="blockBorder">
							<div class="titleS">
								<strong>基本信息</strong>
							</div>
							<div class="tableCont" style="width: 90%;">
								<div class="form-group">
									<label class="col-xs-2 control-label" for="userAccount">用户账号:</label>
									<div class="col-xs-3">
										<input class="form-control" name="map.userAccount" id="userAccount" type="text" placeholder="" />
									</div>
									<div class="col-xs-1">
										<div class="col-xs-1">
											<span class="required">*</span>
										</div>
									</div>
									<label class="col-xs-2 control-label" for="password">用户密码:</label>
									<div class="col-xs-3" style="margin-top: 5px;color: blue;">系统默认初始密码：123456</div>
								</div>
								<div class="form-group">
									<label class="col-xs-2 control-label" for="userName">用户名称:</label>
									<div class="col-xs-3">
										<input class="form-control" name="map.userName" id="userName" type="text" placeholder="" />
									</div>
									<div class="col-xs-1">
										<span class="required">*</span>
									</div>
									<label class="col-xs-2 control-label" for="telphone">手机号码:</label>
									<div class="col-xs-3">
										<input class="form-control" name="map.telphone" id="telphone" type="text" placeholder="" />
									</div>
									<div class="col-xs-1">
										<span class="required"></span>
									</div>
								</div>
							</div>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
